<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}

$acts = array(
	'search', 'public_get_city'
);
$act = in_array($_G['gp_act'], $acts, true) ? $_G['gp_act'] : '';
$dataid = intval(abs($_G['gp_dataid']));
if ( $act == 'search' ){
	$name = $_G['gp_name'];
	if( $name ){
		$customers = limitquery('customer', array('`adminid` > 0', "`name` LIKE '%" . mysql_escape_string($name) . "%'"), array(), 0, 5);
		$adminids = idserialize($customers, 'adminid');
		$admins = parse_array(limitquery('admincp_member', "`id` IN('{$adminids}')", array('select' => '`id`, `groupid`, `companyid`, `departmentid`, `username`, `realname`')));
		$companys = parse_array(limitquery('companys'));
		$departments = parse_array(limitquery('admincp_department'));
		foreach( $customers as $k => $v ){
			$v['name'] = str_replace($name, '<u><font color="#FF0000">'.$name.'</font></u>', $v['name']);
			$customers[$k] = $v;
		}
		foreach( $companys as $k => $v ){
			$v['name'] = substr($v['name'], 0, 6);
			$companys[$k] = $v;
		}
		$datas = array(
			'customers' => $customers,
			'admins' => $admins,
			'companys' => $companys,
			'departments' => $departments
		);
	}
	jsonp($datas, 'data', 0);
}else if( $act == 'public_get_city' ){
	if ( !$dataid || !$city = get_city($dataid) ){
		return false;
	}
	jsonp($city, 'data');
}